package com.wandian.news.mvvm.lifetool.bodyevaluate;

import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.ToastUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.news.R;
import com.wandian.news.databinding.NewsActivityLifeBodyBinding;
import com.wandian.news.databinding.NewsActivityLifeFoodBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 体质查询activity
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_NEWS_BODY)
public class LifeBodyEvaluateActivity extends BaseMVVMActivity<LifeBodyEvaluateViewModel>  {
    private NewsActivityLifeBodyBinding dataBinding;
    private String type = "0";//0男1女
    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.news_activity_life_body);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        initViewData();
        initClink();
    }

    private void initViewData(){
        ActivityUtil.getInstance().showStatusView(this,dataBinding.viewSysTop,true);
        dataBinding.bindTransparentToolBar.toolBarTvTitle.setText("体质查询");
        mViewModel.dataBean.observe(this,dataBean->{
            if(!UIUtils.isEmpty(dataBean) && !UIUtils.isEmpty(dataBean.getNewslist()) && dataBean.getNewslist().size()>0){
                dataBinding.llItem.setVisibility(View.VISIBLE);
                dataBinding.ivDownMore.setVisibility(View.VISIBLE);
                dataBinding.tvBodyBmi.setText("体重指数BMI："+dataBean.getNewslist().get(0).getBmi());
                dataBinding.tvBodyNormbmi.setText("正常BMI指数范围："+dataBean.getNewslist().get(0).getNormbmi());
                dataBinding.tvBodyIdealweight.setText("标准体重："+dataBean.getNewslist().get(0).getIdealweight());
                dataBinding.tvBodyNormweight.setText("正常体重范围："+dataBean.getNewslist().get(0).getNormweight());
                dataBinding.tvBodyTip.setText("身材小贴士："+dataBean.getNewslist().get(0).getTip());
            }

        });
    }

    private void initClink(){
        dataBinding.bindTransparentToolBar.toolBarIvBack.setOnClickListener(v -> finish());

        dataBinding.ivBoy.setOnClickListener(v -> {
            type = "0";
            dataBinding.ivBoy.setImageResource(R.drawable.img_item_choosed);
            dataBinding.ivGirl.setImageResource(R.drawable.img_item_unchoose);
        });
        dataBinding.ivGirl.setOnClickListener(v -> {
            type = "1";
            dataBinding.ivBoy.setImageResource(R.drawable.img_item_unchoose);
            dataBinding.ivGirl.setImageResource(R.drawable.img_item_choosed);
        });

        dataBinding.tvSearch.setOnClickListener(v -> {
            finishhideSoftBoard();
           if(UIUtils.isEmpty(dataBinding.etHeight.getText())){
               ToastUtil.show("请输入身高，单位厘米(cm)");
               return;
           }
            if(UIUtils.isEmpty(dataBinding.etWeight.getText())){
                ToastUtil.show("请输入体重，单位千克(kg)");
                return;
            }
            mViewModel.getData(dataBinding.etHeight.getText().toString(),dataBinding.etWeight.getText().toString(),type);
        });
    }



    @Override
    protected void onDestroy() {
        finishhideSoftBoard();
        super.onDestroy();
    }
}
